package com.aiq.vo;

import com.aiq.constants.ConstantCode;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @ClassName: R
 * @Description: 统一数据的返回对象
 * @Author: vie0134
 * @Date: 2021-01-11 12:46
 * @Version: 1.0
 **/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R {

    /**
     * @Author: vie0134
     * @Description: 常量码
     * @Date: 13:48 2021/1/11
     */
    private int code;
    /**
     * @Author: vie0134
     * @Description:  错误提示
     * @Date: 13:48 2021/1/11
     */
    private String msg;
    /**
     * @Author: vie0134
     * @Description: 返回的数据
     * @Date: 13:48 2021/1/11
     */
    private Object result;

    public static R setSuccess(Object data) {
        R result = new R();
        result.setCode(ConstantCode.SUCCESS);
        result.setMsg("操作成功");
        result.setResult(data);
        return result;
    }

    public static R setError(Object data) {
        R result = new R();
        result.setCode(ConstantCode.ERROR);
        result.setMsg("操作失败");
        result.setResult(data);
        return result;
    }

    public static R setError(Object data, String msg, int code) {
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setResult(data);
        return result;
    }
}
